#ifndef _MAZE_H_
#define _MAZE_H_

#include "point.h"
#include "math.h"
#include "color.h"
#include <vector>
#include <QtOpenGL/qgl.h>

const float kGroundHeight = 0.25;
const float kWallHeight = 1.0;
const float kChange = 0.5; // Wall Tiles that are turned into ground (sort of)
const int kNumHits = 3;

enum Direction { NORTH, EAST, SOUTH, WEST, DIRS };
enum TileType { GROUND, WALL };

class TileNode
{
  int x_;
  int z_;
  bool occupied_;
  bool initial_;
  TileType tile_type_;
  std::vector<TileNode*> neighbours_;
  std::vector<bool> directions_;
  bool visited_;
  int hits_;
  void RenderBox();
  Point GetIni();
  Point GetEnd();

public:
  TileNode(int, int);
  void SetOccupied(bool);
  bool IsOccupied();
  void SetNeighbours(TileNode *n, TileNode *e, TileNode *s, TileNode *w);
  void SetAsInitial();
  void SetType(TileType);
  void SwitchType();
  TileType GetType();
  bool RandomMove();
  void GoThrough(Direction);
  void SetPassage();
  void Shoot();
  void Render();
  void PickRender(GLubyte c[]);
};

class Maze
{
  std::vector< std::vector<TileNode*> > grid_;
  int length_;
  int width_;
  Point ini_;
  Point end_;

public:
  Maze(int width, int length);
  ~Maze();
  void Switch(int, int);
  bool SetOccupied(int, int, bool);
  bool IsOccupied(int, int);
  bool IsGround(int, int);
  bool IsValid(int, int);
  void Shoot(int, int);
  Point GetBoundaryIni();
  Point GetBoundaryEnd();
  Point GetCenter();
  float GetRadius();
  void Render();
  void PickRender();
};

#endif // MAZE_H
